<template>
  <div class="learning-page">
    <!-- 当路由是 /knowledge/learning 时显示卡片 -->
    <div v-if="$route.path === '/knowledge/learning'">
      <h2 class="page-title">学习天地</h2>
      <div class="card-container">
        <!-- 术语卡片 -->
        <el-card 
          class="knowledge-card"
          @click="router.push('/knowledge/learning/words')"
        >
          <div class="card-content">
            <el-icon class="card-icon"><Document /></el-icon>
            <h3>专业术语</h3>
            <p class="card-description">
              专业术语解释与学习，帮助您更好地理解行业专业用语
            </p>
          </div>
          <div class="card-footer">
            <el-button type="primary" text>
              查看详情
              <el-icon class="el-icon--right"><ArrowRight /></el-icon>
            </el-button>
          </div>
        </el-card>

        <!-- 报警卡片 -->
        <el-card 
          class="knowledge-card"
          @click="router.push('/knowledge/learning/alarm')"
        >
          <div class="card-content">
            <el-icon class="card-icon"><Warning /></el-icon>
            <h3>报警知识</h3>
            <p class="card-description">
              常见报警信息解读与处理方法指南
            </p>
          </div>
          <div class="card-footer">
            <el-button type="primary" text>
              查看详情
              <el-icon class="el-icon--right"><ArrowRight /></el-icon>
            </el-button>
          </div>
        </el-card>
      </div>
    </div>

    <!-- 显示子路由内容 -->
    <router-view v-else>
      <template #default="{ Component }">
        <div class="content-view">
          <div class="content-header">
            <el-button @click="router.push('/knowledge/learning')" text>
              <el-icon><Back /></el-icon>
              返回
            </el-button>
            <h2>{{ getTitle }}</h2>
          </div>
          <component :is="Component" />
        </div>
      </template>
    </router-view>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { Document, Warning, ArrowRight, Back } from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()

// 获取标题
const getTitle = computed(() => {
  if (route.path.includes('words')) return '专业术语'
  if (route.path.includes('alarm')) return '报警知识'
  return ''
})
</script>

<style scoped>
.learning-page {
  padding: 24px;
}

.page-title {
  margin-bottom: 24px;
  color: #303133;
  font-size: 24px;
  font-weight: 500;
}

.card-container {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.knowledge-card {
  width: 300px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.knowledge-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
}

.card-content {
  text-align: center;
  padding: 20px;
}

.card-icon {
  font-size: 48px;
  color: #409EFF;
  margin-bottom: 16px;
}

.card-content h3 {
  margin: 0 0 12px;
  color: #303133;
  font-size: 18px;
  font-weight: 500;
}

.card-description {
  color: #606266;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  min-height: 42px;
}

.card-footer {
  border-top: 1px solid #EBEEF5;
  padding: 12px 20px;
  text-align: right;
}

:deep(.el-card__body) {
  padding: 0;
}

/* 响应式布局 */
@media (max-width: 768px) {
  .card-container {
    justify-content: center;
  }
  
  .knowledge-card {
    width: 100%;
    max-width: 300px;
  }
}

.content-view {
  min-height: 400px;
}

.content-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #EBEEF5;
}

.content-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
  color: #303133;
}

:deep(.el-button) {
  display: flex;
  align-items: center;
  gap: 4px;
}
</style> 